#include<stdio.h>
#include<stdlib.h>
#include<conio.h>               //get the ASCII of up, down, left and right
#include<windows.h>
#include<mmsystem.h>
#pragma comment(lib,"winmm.lib") //PlaySound()
#include<time.h>
#include<algorithm>
using namespace std;

void draw1(int maze[20][20]);
void draw3(int maze[43][43]);
void menu();
void move1(int maze[20][20]);
void move3(int maze[43][43]);


//easy
int maze1[20][20] = {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
		            {4,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1},
		            {1,1,1,0,0,1,1,1,0,0,1,0,0,0,0,0,1,0,0,1},
		            {1,1,1,0,0,1,1,1,0,0,1,1,1,1,0,0,1,0,0,1},
		            {1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,0,0,1},
		            {1,0,0,1,1,1,1,1,1,0,0,1,1,1,0,0,1,0,0,1},
		            {1,0,0,1,1,1,1,1,1,0,0,1,0,0,0,0,1,0,0,1},
		            {1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,1},
		            {1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,1},
		            {1,0,0,1,1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,1},
		            {1,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1},
		            {1,0,0,0,0,0,0,1,1,0,0,1,1,1,1,0,0,1,1,1},
		            {1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1},
		            {1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,0,0,0,1},
		            {1,0,0,0,0,0,0,1,0,0,0,1,1,1,1,0,1,0,0,1},
		            {1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,1},
		            {1,0,0,1,1,1,1,1,0,1,1,1,1,0,0,0,0,0,1,1},
		            {1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,1},
		            {1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0},
		            {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};


//ordinary
int maze2[20][20] = {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
		            {4,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1},
		            {1,1,1,0,0,1,1,1,0,0,1,0,0,0,0,0,1,0,0,1},
		            {1,1,1,0,0,1,1,1,0,0,1,1,1,1,0,0,1,0,0,1},
		            {1,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,0,0,1},
		            {1,0,0,1,1,1,1,1,1,0,0,1,1,1,0,0,1,0,0,1},
		            {1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,1},
		            {1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,1},
		            {1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,1},
		            {1,0,0,1,1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,1},
		            {1,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1},
		            {1,0,0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1},
		            {1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1},
		            {1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,0,0,0,1},
		            {1,0,0,0,0,0,0,1,0,0,0,1,1,1,1,0,1,0,0,1},
		            {1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1,1,1},
		            {1,0,0,1,1,1,1,1,0,1,1,1,1,0,0,0,0,0,1,1},
		            {1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,1},
		            {1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0},
		            {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};


//hard
int maze3[43][43] = {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                     {1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                     {1,0,1,1,1,1,1,1,1,0,1,0,1,0,1,1,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,0,1},
                     {1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,1},
                     {1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1,1,1,1,0,1,0,0,1},
                     {1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,1},
                     {1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1},
                     {1,0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1},
                     {1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1},
                     {0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0,1,0,4},
                     {1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,1,1,1,1,1,0,0,1,0,1,0,1,0,1,0,1},
                     {1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,0,0,0,1,0,1},
                     {1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,0,1,0,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,0,1},
                     {1,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1},
                     {1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1},
                     {1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1},
                     {1,0,1,0,1,0,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,0,1,0,1},
                     {1,0,0,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,0,1,0,1},
                     {1,1,1,1,1,0,1,0,1,1,1,0,1,0,1,0,1,0,1,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,1,0,1},
                     {1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,1},
                     {1,0,1,0,1,0,1,0,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1},
                     {1,0,0,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1},
                     {1,0,0,0,1,1,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1},
                     {1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1},
                     {1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1},
                     {1,1,1,1,1,0,1,1,1,0,1,0,0,0,1,1,1,1,1,0,0,1,1,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,0,1,0,0,1},
                     {1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0,1,0,0,1},
                     {1,0,1,0,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,1},
                     {1,0,1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,0,1},
                     {1,0,1,0,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1,1,1,0,0,1},
                     {1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,0,1},
                     {1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,1,1,0,0,1,1,1,1,1,0,1,0,1,0,1,0,1,0,0,1},
                     {1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,0,1},
                     {1,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,1,1,1,0,1,0,1,0,1,0,1,0,0,1},
                     {1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,1},
                     {1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,0,1,0,1,0,0,1},
                     {1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1},
                     {1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,1,1},
                     {1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1},
                     {1,0,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1},
                     {1,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                     {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};


//画迷宫1
void draw1(int maze[20][20]){
    int i,j;
    for(i = 0;i < 20;i ++){
        printf("\t\t\t");                          //display int the center of the screen
        for(j = 0;j < 20;j ++){
            if(maze[i][j] == 4) printf("*");       //4---you
            else if(maze[i][j] == 0) printf(" ");  //0---road
            else printf("#");                      //1---wall
        }
        printf("\n");
    }
}


//画迷宫3
void draw3(int maze[43][43]){
    int i,j;
    for(i = 0;i < 43;i ++){
        printf("\t\t\t");                          //display int the center of the screen
        for(j = 0;j < 43;j ++){
            if(maze[i][j] == 4) printf("*");       //4---you
            else if(maze[i][j] == 0) printf(" ");  //0---road
            else printf("#");                      //1---wall
        }
        printf("\n");
    }
}


//menu
void menu(){
    int bgm,level;
	system("color 0D");  //color
	//system("pause");
	//PlaySound("1.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
	//mciSendString("open D:\\Code\\1.wav",NULL,0,NULL);
    printf("\n\t\t\t");
    for(int i = 0;i < 20;i ++){
        printf("-");  //输出界面上界
    }
    printf("\n");
    printf("The * is the symbol of you.\n");  //*表示你所处的位置
    printf("You can press (up,down,left,right) to move the (*).\n");  //你可以按上、下、左右键控制移动
    printf("If your keyboard doesn't have these buttons,you can also press (w,s,a,d) to move the (*).\n");  //也可以按w/s/a/d控制移动
    printf("Please choose the BGM, you can choose 1,2,3 or 0--exit:");  //choose BGM
    scanf("%d",&bgm);
    switch(bgm){
        case 1:PlaySound("1.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
        case 2:PlaySound("2.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
        case 3:PlaySound("3.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
        case 0:return;break;
        default:break;
    }
    printf("Please choose the level of the maze, you can choose 1--easy,2--ordinary,3--hard,0--exit,please input the number:");
    scanf("%d",&level);
    if(bgm != 0) printf("Please press Enter to enter the maze.\n");  //请按回车键进入游戏界面
    getch();  //don't show in the screen,不回显
    system("cls");  //清屏
    switch(level){
        case 1:draw1(maze1);move1(maze1);break;
        case 2:draw1(maze2);move1(maze2);break;
        case 3:draw3(maze3);move3(maze3);break;
        case 0:return;break;
        default:break;
    }
}


//移动1
void move1(int maze[20][20]){
    int a = 1;  //row
    int b = 0;  //col
    char num;
    do{
        num = getch();
        //only change four locations of *
        switch(num){
            case 72:  //↑的ASCII
            case 87:  //大写W的ASCII
            case 119: //小写w的ASCII
            if(maze[a-1][b] != 1){  //up
                swap(maze[a][b],maze[a-1][b]);
                a --;
                system("cls");  //clear the screen
                draw1(maze);
                break;
            }
            break;
            case 80:
            case 83:
            case 115:
            if(maze[a+1][b] != 1){  //down
                swap(maze[a+1][b],maze[a][b]);
                a ++;
                system("cls");
                draw1(maze);
                break;
            }
            break;
            case 75:
            case 65:
            case 97:
            if(maze[a][b-1] != 1){  //left
                swap(maze[a][b-1],maze[a][b]);
                b --;
                system("cls");
                draw1(maze);
                break;
            }
            break;
            case 77:
            case 68:
            case 100:
            if(maze[a][b+1] != 1){  //right
                swap(maze[a][b+1],maze[a][b]);
                b ++;
                system("cls");
                draw1(maze);
                break;
            }
            break;
            default:break;
        }
        if(maze[18][19] == 4){
            printf("\n\t\t    Happy Children's Day to you!\n\n\n");
            Sleep(2000);  //delay
            //if(++n != 1) //printf("Please press Enter to return the maze.\n");  //请按回车键返回主界面
            //Sleep(2000);  //delay
            break;
        }
    }while(1);
    system("cls");
    menu();
}


//移动3
void move3(int maze[43][43]){
    int a = 9;  //row
    int b = 42;  //col
    char num;
    do{
        num = getch();
        //only change four locations of *
        switch(num){
            case 72:  //↑的ASCII
            case 87:  //大写W的ASCII
            case 119: //小写w的ASCII
            if(maze[a-1][b] != 1){  //up
                swap(maze[a][b],maze[a-1][b]);
                a --;
                system("cls");  //clear the screen
                draw3(maze);
                break;
            }
            break;
            case 80:
            case 83:
            case 115:
            if(maze[a+1][b] != 1){  //down
                swap(maze[a+1][b],maze[a][b]);
                a ++;
                system("cls");
                draw3(maze);
                break;
            }
            break;
            case 75:
            case 65:
            case 97:
            if(maze[a][b-1] != 1){  //left
                swap(maze[a][b-1],maze[a][b]);
                b --;
                system("cls");
                draw3(maze);
                break;
            }
            break;
            case 77:
            case 68:
            case 100:
            if(maze[a][b+1] != 1){  //right
                swap(maze[a][b+1],maze[a][b]);
                b ++;
                system("cls");
                draw3(maze);
                break;
            }
            break;
            default:break;
        }
        if(maze[9][0] == 4){
            printf("\n\t\t\t\tHappy Children's Day to you!\n\n\n");
            Sleep(2000);  //delay
            //if(++n != 1) //printf("Please press Enter to return the maze.\n");  //请按回车键返回主界面
            //Sleep(2000);  //delay
            break;
        }
    }while(1);
    system("cls");
    menu();
}



int main(){
    menu();
    return 0;
}
